/**
 * Copyright (c) 2018-2028, LookAhead.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.lookahead.parent.apidoc.struct;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 系列表数据传输对象实体类
 *
 * @author Lookahead
 * @since 2021-06-23
 */
@Data
@NoArgsConstructor
public class TreeDTO implements Serializable {

    private static final long serialVersionUID = 7075986247626635115L;

    @JsonSerialize(using = ToStringSerializer.class)
    @Schema(description = "节点ID")
    private Long id;

    @Schema(description = "节点名称")
    private String name;

    @Schema(description = "节点层级")
    private Integer level;

    @Schema(description = "子节点")
    private List<TreeDTO> children = null;

    public TreeDTO(Long id, String name) {
        this.id = id;
        this.name = name;
        this.level = -1;
        this.children = Collections.emptyList();
    }

    public TreeDTO(Long id, String name, Integer level) {
        this.id = id;
        this.name = name;
        this.level = level;
        this.children = Collections.emptyList();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        final TreeDTO other = (TreeDTO) obj;
        return Objects.equals(this.id, other.id) && Objects.equals(this.name, other.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name);
    }
}
